#include <iostream>
#include <future>
#include <chrono>
#include <thread>
using namespace std;
int Add(int num1, int num2)
{
    this_thread::sleep_for(chrono::seconds(3));
    cout << "int Add(int num1, int num2)" << endl;
    return num1 + num2;
}
int main()
{
    // async策略：定义时便开始执行直到被获取
    // deferred策略：只有在获取时才执行
    // future<int> fut = async(launch::async, Add, 11, 22);
    future<int> fut = async(launch::deferred, Add, 11, 22);
    cout << "----------------------1----------------------" << endl;
    this_thread::sleep_for(chrono::seconds(5));
    cout << "----------------------2----------------------" << endl;
    int ret = fut.get();
    cout << "----------------------3----------------------" << endl;
    cout << ret << endl;
    return 0;
}